package com.pd.backend.service.impl;

import com.pd.backend.entity.PdOrderLocation;
import com.pd.backend.dao.PdOrderLocationDao;
import com.pd.backend.service.PdOrderLocationService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 订单位置信息 (PdOrderLocation)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:34
 */
@Service("pdOrderLocationService")
public class PdOrderLocationServiceImpl implements PdOrderLocationService {
    @Resource
    private PdOrderLocationDao pdOrderLocationDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PdOrderLocation queryById(String id) {
        return this.pdOrderLocationDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pdOrderLocation 筛选条件
     * @param pageRequest     分页对象
     * @return 查询结果
     */
    @Override
    public Page<PdOrderLocation> queryByPage(PdOrderLocation pdOrderLocation, PageRequest pageRequest) {
        long total = this.pdOrderLocationDao.count(pdOrderLocation);
        return new PageImpl<>(this.pdOrderLocationDao.queryAllByLimit(pdOrderLocation, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pdOrderLocation 实例对象
     * @return 实例对象
     */
    @Override
    public PdOrderLocation insert(PdOrderLocation pdOrderLocation) {
        this.pdOrderLocationDao.insert(pdOrderLocation);
        return pdOrderLocation;
    }

    /**
     * 修改数据
     *
     * @param pdOrderLocation 实例对象
     * @return 实例对象
     */
    @Override
    public PdOrderLocation update(PdOrderLocation pdOrderLocation) {
        this.pdOrderLocationDao.update(pdOrderLocation);
        return this.queryById(pdOrderLocation.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.pdOrderLocationDao.deleteById(id) > 0;
    }
}
